﻿using UnityEngine;
using System.Collections;

public class PlayerStateController : MonoBehaviour {
	//possiveis estados do jogador
	public enum playerState
	{
		idle = 0,
		left, //walking
		right,//walking
		jumping,
		landing,
		falling,
		attacking,
		defending,
		casting,
		lDashing,
		rDashing,
		flyForm,
		waterForm,
		dead,
		jumpMoving,
		_stateCount
	}

	public enum playerForm
	{
		humanForm = 0,
		waterForm,
		flyForm
	}

	// variavel para o tempo de daley entre a transiçoes dos estados
	public static float[] stateDelayTimer = new float[(int)playerState._stateCount];

	public delegate void PlayerStatehandler(PlayerStateController.playerState newState);
	public static event PlayerStatehandler onStateChange;

	void LateUpdate()
	{
		if (onStateChange != null)
		{
			float horizontal = Input.GetAxis("Horizontal");
			if (horizontal != 0.0f) 
			{	
				if(horizontal < 0.0f)
				{
					onStateChange(PlayerStateController.playerState.left);
				}
				else
				{
					onStateChange(PlayerStateController.playerState.right);
				}
			}
			else
			{	
				onStateChange(PlayerStateController.playerState.idle);
			}
			
			float jump = Input.GetAxis("Jump");
			if(jump > 0.0f)
			{
				onStateChange(PlayerStateController.playerState.jumping);
			}

			float attack = Input.GetAxis("Attack");
			if(attack > 0.0f)
			{
				onStateChange(PlayerStateController.playerState.attacking);
			}

			float ldash = Input.GetAxis("LDash");
			if(ldash > 0.0f)
			{
				onStateChange(PlayerStateController.playerState.lDashing);
			}

			float rdash = Input.GetAxis("RDash");
			if(rdash > 0.0f)
			{
				onStateChange(PlayerStateController.playerState.rDashing);
			}

			float waterForm = Input.GetAxis("WaterForm");
			if(waterForm > 0.0f)
			{
				onStateChange(PlayerStateController.playerState.waterForm);
			}

			float flyForm = Input.GetAxis("FlyingForm");
			if(flyForm > 0.0f)
			{
				onStateChange(PlayerStateController.playerState.flyForm);
			}
		}
	}
}
